package net.mcreator.infinite_storage.procedure;

import net.minecraft.world.World;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.item.ItemStack;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.Container;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.Entity;

import net.mcreator.infinite_storage.gui.GuiInfiniteBagGui;
import net.mcreator.infinite_storage.InfiniteStorageMod;
import net.mcreator.infinite_storage.ElementsInfiniteStorageMod;

import java.util.function.Supplier;
import java.util.Map;
import java.util.HashMap;

@ElementsInfiniteStorageMod.ModElement.Tag
public class ProcedureInfiniteBagPageLast extends ElementsInfiniteStorageMod.ModElement {
	public ProcedureInfiniteBagPageLast(ElementsInfiniteStorageMod instance) {
		super(instance, 56);
	}
	static Map<String, Object> $_dependencies = new HashMap<>();
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("entity") == null) {
			return;
		}
		if (dependencies.get("x") == null) {
			return;
		}
		if (dependencies.get("y") == null) {
			return;
		}
		if (dependencies.get("z") == null) {
			return;
		}
		if (dependencies.get("world") == null) {
			return;
		}
		Entity entity = (Entity) dependencies.get("entity");
		int x = (int) dependencies.get("x");
		int y = (int) dependencies.get("y");
		int z = (int) dependencies.get("z");
		World world = (World) dependencies.get("world");
		NBTTagCompound InfiniteBag = entity.getEntityData().getCompoundTag("InfiniteBag");
		if ((InfiniteBag.getDouble("InfiniteBagPage") > 0)) {
			{
				$_dependencies.put("entity", entity);
				ProcedureInfiniteBagGuiClose.executeProcedure($_dependencies);
			}
			for (int index0 = 0; index0 < (int) (54); index0++) {
				if (entity instanceof EntityPlayerMP) {
					Container _current = ((EntityPlayerMP) entity).openContainer;
					if (_current instanceof Supplier) {
						Object invobj = ((Supplier) _current).get();
						if (invobj instanceof Map) {
							ItemStack _setstack = (ItemStack.EMPTY);
							_setstack.setCount((int) 1);
							((Slot) ((Map) invobj).get((int) (index0))).putStack(_setstack);
							_current.detectAndSendChanges();
						}
					}
				}
			}
			InfiniteBag.setDouble("InfiniteBagPage", (InfiniteBag.getDouble("InfiniteBagPage") - 1));
			entity.getEntityData().setTag("InfiniteBag", InfiniteBag);
			{
				$_dependencies.put("entity", entity);
				ProcedureInfiniteBagGuiOpen.executeProcedure($_dependencies);
			}
		} else {
			InfiniteBag.setDouble("InfiniteBagPage", 0);
		}
		entity.getEntityData().setTag("InfiniteBag", InfiniteBag);
		if (entity instanceof EntityPlayer)
			((EntityPlayer) entity).openGui(InfiniteStorageMod.instance, GuiInfiniteBagGui.GUIID, world, x, y, z);
	}
}
